package com.wisdudu.blank.app;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.orhanobut.hawk.Hawk;
import com.orhanobut.hawk.HawkBuilder;
import com.orhanobut.hawk.LogLevel;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.Settings;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
import com.wisdudu.blank.BuildConfig;
import com.wisdudu.blank.support.util.ToastUtil;

import io.realm.Realm;


/**
 * Created by qyf on 2016/8/11.
 */

public class App extends Application {
    public static App instance = null;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initDebug();
        initTools();
        initDataSource();
    }


    private void initTools() {
        ToastUtil.INSTANCE.init(this);
    }

    private void initDataSource() {
        Hawk.init(instance)
                .setEncryptionMethod(HawkBuilder.EncryptionMethod.NO_ENCRYPTION)
                .setStorage(HawkBuilder.newSharedPrefStorage(instance))
                .setLogLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE)
                .build();
//        Stetho.initializeWithDefaults(instance);
        Realm.init(this);
        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                        .build());
    }

    private void initDebug() {
        Logger.initialize(new Settings()
                .isShowMethodLink(true)
                .isShowThreadInfo(false)
                .setLogPriority(BuildConfig.DEBUG ? Log.VERBOSE : Log.ERROR)
                .setMethodOffset(0));
    }

    public static Context getContext() {
        return instance;
    }

}
